const vcl = new VclUtil("http://localhost:8051");
vcl.plusReady().then(async () => {
    const {createStore} = Vuex;
    const {createApp} = Vue;
    const bus = mitt();


    // 路由管理
    const Index =  () => httpLoader("./template/pages/index.vue");

    const Login =  () => httpLoader("./template/pages/login.vue");
    const routes =  [
        {path: '/login', component: Login},
        {path: '/', component: Index},
    ]

    const router = VueRouter.createRouter({
        history: VueRouter.createWebHashHistory(),  //  内部提供了 history 模式的实现。为了简单起见，我们在这里使用 hash 模式。
        routes, // `routes: routes` 的缩写
    });

    router.beforeEach(async (to) => {
        // if(!Array.of("/login").includes(to.path) && !localStorage.getItem("loginUser")){
        //     return '/login'
        // }
    });

    // 状态管理
    const store = createStore({
        state() {
            return {
                count: 0,
            }
        },
        getters: { // 派生操作
            getUser() {
                const user = localStorage.getItem("loginUser");
                return user ? JSON.parse(user):null;
            }
        },
        mutations: { // 同步操作

        },
        actions: { // 异步操作

        }
    })


    // 组件初始化
    const App = await httpLoader("./template/App.vue");
    let app = createApp(App);
    app.config.globalProperties.$bus=bus;  // 配置vcl后续全局引用
    app.use(router);
    app.use(store);
    app.mount('#app');
});


const HttpVueLoader = {
    install(Vue,options){
        //code
    }
}
